package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.entity.Sku;
import com.leyou.item.mapper.SkuMapper;
import com.leyou.item.service.SkuService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuService {
    @Override
    public void minusStock(Map<Long, Integer> cartsMap){
        executeBatch(sqlSession -> {
            cartsMap.entrySet().forEach(cart->{
                Map<String, Object> paramMap=new HashMap<>();
                paramMap.put("skuId",cart.getKey());
                paramMap.put("num",cart.getValue());
                sqlSession.update("com.leyou.item.mapper.SkuMapper.minusStock",paramMap);
            });
            sqlSession.flushStatements();
        });
    }
}